﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CloudReader.Net.Server
{
    /// <summary>
    /// 连接池
    /// </summary>
    public class ConnectionPool
    {
        public List<Connection> _conn;
        public ConnectionPool() => _conn = new List<Connection>();

        public List<Connection> GetEnumerator() => _conn;

        public void Push(Connection c)
        {
            _conn.Add(c);
        }
        public void Remove(Connection c)
        {
            _conn.Remove(c);
        }
        public void Remove(string Context)
        {
            foreach(var i in _conn)
            {
                if(i.Context == Context)
                {
                    _conn.Remove(i);
                }
            }
        }
        public Connection this[int index] => _conn[index];
        public Connection this[string context]
        {
            get
            {
                Connection c = null;
                foreach (var i in _conn)
                {
                    if (i.Context == context)
                        c = i;
                }
                return c;
            }
        }

    }
}
